package com.oha.myutils.services;

import javax.jms.Connection;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.log4j.Logger;

import com.ibm.mq.jms.MQConnectionFactory;
import com.ibm.mq.jms.MQQueue;
import com.ibm.msg.client.wmq.WMQConstants;

public class WebsphereMQService {
	
	private static Logger log4j = Logger.getLogger(WebsphereMQService.class);
	
	public void enviarMessage(String txtMsg){
		try{
			MQConnectionFactory mq = new MQConnectionFactory();
			mq.setTransportType(1);//Se envia como cliente
			mq.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
			mq.setHostName("AXPREMB");
			mq.setPort(1616);
			mq.setChannel("SC.CONNEXT");
			mq.setQueueManager("QM.CVP");
			Connection c = mq.createConnection("srvcsgecore", "u2H90rr5E7");
			MQQueue q = new MQQueue("INFOECOM.ISU4");//PDA.ISU4, COREISU4.ERRORES, RFID.ISU4, TGT.ISU4, ECOM.ISU4
		    Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
		    MessageProducer producer = s.createProducer(q);
		    TextMessage message = s.createTextMessage(txtMsg.trim());
		    producer.send(message);
		    c.close();
		}catch(Exception e){
			log4j.error("Exception:", e);
		}
	}
	
}
